package com.older.wptsb.config;

import org.springframework.amqp.core.Binding;
import org.springframework.amqp.core.BindingBuilder;
import org.springframework.amqp.core.DirectExchange;
import org.springframework.amqp.core.Queue;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

@Configuration
public class RabbitMQConfig {
    // 定义队列名称
    public static final String ALERT_QUEUE_FAMILY = "alert.queue.family";
    public static final String ALERT_QUEUE_COMMUNITY = "alert.queue.community";

    // 定义交换机名称
    public static final String ALERT_EXCHANGE = "alert.exchange";

    // 定义路由键
    public static final String ALERT_ROUTING_KEY_FAMILY = "alert.routing.key.family";
    public static final String ALERT_ROUTING_KEY_COMMUNITY = "alert.routing.key.community";

    // 创建队列
    @Bean
    public Queue familyAlertQueue() {
        return new Queue(ALERT_QUEUE_FAMILY, true);
    }

    @Bean
    public Queue communityAlertQueue() {
        return new Queue(ALERT_QUEUE_COMMUNITY, true);
    }

    // 创建交换机
    @Bean
    public DirectExchange alertExchange() {
        return new DirectExchange(ALERT_EXCHANGE);
    }

    // 绑定队列到交换机
    @Bean
    public Binding bindingFamilyAlertQueue(Queue familyAlertQueue, DirectExchange alertExchange) {
        return BindingBuilder.bind(familyAlertQueue).to(alertExchange).with(ALERT_ROUTING_KEY_FAMILY);
    }

    @Bean
    public Binding bindingCommunityAlertQueue(Queue communityAlertQueue, DirectExchange alertExchange) {
        return BindingBuilder.bind(communityAlertQueue).to(alertExchange).with(ALERT_ROUTING_KEY_COMMUNITY);
    }
}
